<?php

class Auth_handle extends CI_Model {

    const Statustrue = True;
    const Statusflase = False;

    function __construct() {
        $this->load->helper('fuc');
        $this->load->library('topclass');
        $this->load->library('session_db');
        $this->config->load('topapiconfig');
        parent::__construct();
    }

    function login_action() {//top授权处理流程
        $this->load->library('parameter', array("get" => $_GET["top_parameters"]));
        return $this->parameter->getParamArray();
    }

    function login_gettopsession() {//top授权处理流程
        $top_parameters_array = $this->login_action();
        $usernick = $top_parameters_array["visitor_nick"]; //通过链接获得用户昵称  
        
        $this->session_db->write_Sessiondb("usernick", $usernick);
        $top_session = $_GET["top_session"];
       
        $top_appkey = $_GET["top_appkey"];
        $top_parameters = $_GET["top_parameters"];
        $top_session = $_GET["top_session"];
        $this->session_db->write_Sessiondb("top_session", $top_session);
      
        $appsetingarray = $this->config->item('top_commentwall_setting');
        $secret = $appsetingarray["behidend"]["appsecck"];
        $top_sign = $_GET["top_sign"];
        return $sign = base64_encode(md5($top_appkey . $top_parameters . $top_session . $secret, true));
    }

    function logout_action() {//退出系统
//写入退出时间
        $userid_my = $this->session_db->get_Sessiondb("userid_my");
        $this->session_db->destory_Sessiondb();
        $time = time();
        $sql = "update user set last_login =\"{$time}\" where uid=\"{$userid_my}\" ";
        $this->db->query($sql);
        redirect('login/index', 'location', 301);
    }

    function isLogin_statues() {//判定sessiondb状态是否处于登陆如果没有跳转登陆
        if (!($this->session_db->get_Sessiondb("statue") == "login")) {
            $url = site_url("login/index");
            redirect($url, 'location');
        }
    }

    function decis_last_time() {
        $this->session_db->decis_last_time();
    }

}

?>
